<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>zTree</title>
    <link rel="stylesheet" href="../plugins/ztree/css/demo.css">
    <link rel="stylesheet" href="../plugins/ztree/css/zTreeStyle/zTreeStyle.css">
    <script src="../plugins/ztree/js/jquery-1.4.4.min.js"></script>
    <script src="../plugins/ztree/js/jquery.ztree.all-3.5.js"></script>
    <script>
        var zTreeObj;
        var setting = { data: {
                simpleData: {
                    enable: true // 开启简单json数据结构
                }
            },
            check: {
                enable: true
            }};
        //标准类型
        /*var setting = {};*/
      /*  var zNodes = [
            {name:"test1",open:true,children:[{name: "test1_1"},{name:"test1_2"}]},
            {name:"test2",open:true,children:[{name: "test2_1"},{name:"test2_2"}]}
        ];*/
      //简单类型
        var  zNodes = [
            {id:1, pId:0, name: "父节点"},
            {id:11, pId:1, name: "子节点1"},
            {id:12, pId:1, name: "子节点2",checked:true},
            {id:111,pId:11,name:"子节点11"},
            {id:222,pId:12,name:"子节点12"},
        ];
        $(document).ready(function () {
            zTreeObj = $.fn.zTree.init($("#treeDemo"),setting,zNodes)
            zTreeObj.expandAll(true);

            $('#addCheck').click(function () {
                var nodes = zTreeObj.getCheckedNodes(true);
                for (let node of nodes) {
                    console.log(node.id);
                }
            })
        });
    </script>
</head>
<body>
<div>
    <ul id="treeDemo" class="ztree"></ul>
</div>
</body>
</html>